package com.study.demo1;


import java.util.Arrays;
import java.util.Comparator;

public class demo {
    
    public static void main(String[] args){

        int[] i = new int[]{3423,33,456};

        System.out.println(largestNumber(i));
    }

    public void m1(){
        String[] arr = new String[]{"E","S","W","N"};

        String start ="3 3 E";

        String mov = "MMRMMRMRRM";

        String[] split = start.split(" ");

        Integer i = Integer.parseInt(split[0]);
        Integer j = Integer.parseInt(split[1]);
        String k = split[2];
        int index;
        for (index=0;index<arr.length;index++){
            if (k.equals(arr[index])){
                break;
            }
        }

        String[] strings = mov.split("");

        for (String s:strings) {
            switch (s){
                case "L":
                    index--;
                    if (index==-1){
                        index=3;
                    }
                    break;
                case "R" :
                    index++;
                    if (index==4){
                        index=0;
                    }
                    break;
                case "M" :
                    switch (arr[index]){
                        case "E":
                            i++;
                            break;
                        case "S":
                            j--;
                            break;
                        case "W":
                            i--;
                            break;
                        case "N":
                            j++;
                            break;
                        default:
                            break;
                    }
                    break;
                default:
                    break;
            }
        }

        System.out.println(i+" "+j +" "+ arr[index]);
    }



    public static String largestNumber(int[] num) {
        String str = new String();
        if(num.length == 0)
            return str;

        String[] strs = new String[num.length];
        for(int i = 0; i < num.length; i++){
            strs[i] = String.valueOf(num[i]);   //将int型数组转化为字符数组 方便cmp中的拼接 int型拼接不知道位数不好操作
        }

        Arrays.sort(strs, new Cmp());

        if(strs[num.length - 1].equals("0")) return "0";  //num[]中是一串0
        for(int i = num.length - 1; i >= 0; i--){ //将排序后的字符拼接起来
            str = str + strs[i];
        }

        return str;
    }



}

class Cmp implements Comparator<String> {   //***
    public int compare(String a, String b){ //返回int
        String ab = a + b;
        String ba = b + a;
        return Integer.parseInt(ab) - Integer.parseInt(ba); //***
    }
}